import resolve from '@rollup/plugin-node-resolve';
import vuePlugin from '@vitejs/plugin-vue';
import postcss from 'rollup-plugin-postcss';
import autoprefixer from 'autoprefixer';
import path from 'path';
import { fileURLToPath } from 'url';
import copy from 'rollup-plugin-copy'
import url from 'postcss-url';


const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default {
    input: './packages/components/index.js',
    output: [
        {
            file: 'dist/es.js',
            name: "XHUI",
            format: 'es',
        },
        {
            file: "dist/cjs.js",
            name: "XHUI",
            format: "cjs",
            exports: "named",
        },
        {
            file: "dist/umd.js",
            name: "XHUI",
            format: "umd",
            exports: "named",
            globals: {
                vue: "Vue",
            },
        },
    ],
    plugins: [
        resolve(),
        vuePlugin(),
        postcss({
            extract: path.resolve(__dirname, 'dist/theme-chalk/style.css'), // 提取css到单独文件中
            plugins: [autoprefixer(),
            url({
                url: 'copy',
                basePath: "fonts",
                assetsPath: "fonts"
            })
            ] // 自动添加前缀
        }),
        // 将packages/theme-chalk/fonts目录下的所有文件复制到dist/theme-chalk/fonts目录下
        copy({
            targets: [{ src: "packages/theme-chalk/fonts/*", dest: "dist/theme-chalk/fonts/" }]
        })
    ],
    external: ['vue'], // 依赖模块
};